from ckeditor.fields import RichTextField
from django.db import models
from django.utils.translation import gettext_lazy as _


class HomePage(models.Model):
    company_name = models.CharField(verbose_name=_('企业名称'), max_length=100, default='')
    logo_circular = models.ImageField(verbose_name=_('圆形LOGO'), null=True, blank=True, upload_to='media/logo/%Y%m/')
    logo_square = models.ImageField(verbose_name=_('方型LOGO'), null=True, blank=True, upload_to='media/logo/%Y%m/')
    slogan = models.CharField(verbose_name=_('口号'), max_length=100, default='')
    intro_tab = models.CharField(verbose_name=_('导航1'), max_length=100, default='')
    gallery_tab = models.CharField(verbose_name=_('导航2'), max_length=100, default='')
    contact_tab = models.CharField(verbose_name=_('导航3'), max_length=100, default='')

    title = models.CharField(verbose_name=_('首页标题'), max_length=255, null=True, blank=True)
    body = RichTextField(verbose_name=_('首页内容'), max_length=2000, null=True, blank=True)

    gallery_desc = RichTextField(verbose_name=_('副页介绍'), max_length=2000, null=True, blank=True)

    contact_title = models.CharField(verbose_name=_('联系方式标题'), max_length=255, null=True, blank=True)
    contact_content = RichTextField(verbose_name=_('联系方式介绍'), max_length=2000, null=True, blank=True)
    contact_body = RichTextField(verbose_name=_('联系方式内容'), max_length=2000, null=True, blank=True)

    copyright = models.CharField(verbose_name=_('copyright'), max_length=255, null=True, blank=True)
    beian = models.CharField(verbose_name=_('备案号'), max_length=255, null=True, blank=True)
    is_show = models.BooleanField(verbose_name=_('是否呈现'), default=True)

    datetime_created = models.DateTimeField(verbose_name=_('创建时间'), auto_now_add=True)
    datetime_updated = models.DateTimeField(verbose_name=_('更新时间'), auto_now=True)

    objects = models.Manager()

    class Meta:
        ordering = ['-id']
        verbose_name = _('官网页面')
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{0}".format(self.company_name)


class Gallery(models.Model):
    related_page = models.ForeignKey(
        HomePage,
        on_delete=models.CASCADE,
        null=True,
        verbose_name=_('关联页面')
    )
    image_name = models.CharField(verbose_name=_('图片名称'), max_length=255, null=True, blank=True)
    image = models.ImageField(verbose_name=_('图片'), upload_to='media/gallery/%Y%m/')

    objects = models.Manager()

    class Meta:
        ordering = ['-id']
        verbose_name = _('副页图片')
        verbose_name_plural = verbose_name

    def __str__(self):
        return "{0}".format(self.image_name)
